//
//  BaseViewController.swift
//  StoreProject
//
//  Created by CYC on 1998/12/29.
//

import UIKit

class BaseViewController: UIViewController {
    
    var navView: UIView?        // 整个导航栏
    var backButton: UIButton?   // 返回按钮
    var titleLabel: UILabel?    // 标题
    var navLine: UIView?        // 导航栏底部那根线
    var backIcon: UIImageView?  // 返回按钮图片
    var noDataLabel: UILabel?
    var titleButton: UIButton?  // 标题按钮


    // MARK:======================================私有方法========================================
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = kBGColor
        self.view.clipsToBounds = true
        self.navigationController?.navigationBar.isHidden = true;
        
        let view1 = UIView.init(frame: .init(x: 0, y: 0, width: kScreenWidth, height: kNavHeight))
        view1.backgroundColor = .white
        self.view.addSubview(view1)
        navView = view1
        
        // 返回按钮
        let btn = UIButton.init(frame: CGRect.init(x: 0, y: view1.c_height() - 44.0, width: 80.0, height: 44.0))
        view1.addSubview(btn)
        self.backButton = btn
        
        let icon1 = UIImageView.init(frame: CGRect.init(x:15, y: 0, width: 15, height: btn.c_height()))
        icon1.c_image( "1")
        icon1.contentMode = .scaleAspectFit
        btn.addSubview(icon1)
        self.backIcon = icon1
        
        // 标题
        let lab1 = UILabel.init(frame: CGRect.init(x: btn.c_right(), y: btn.c_top(), width: kScreenWidth - btn.c_right()*2, height: btn.c_height()))
        lab1.textColor = kLabelColor1
        lab1.textAlignment = .center
        lab1.adjustsFontSizeToFitWidth = true
        lab1.font = kBFont(20)
        view1.addSubview(lab1)
        self.titleLabel = lab1
        
        let btn2 = UIButton.init(frame: lab1.frame)
        view1.addSubview(btn2)
        self.titleButton = btn2
        
        let line = UIView.init(frame: CGRect.init(x: 0, y: view1.c_height() - kLineSize, width: view1.c_width(), height: kLineSize))
        line.backgroundColor = kLineColor
        view1.addSubview(line)
        self.navLine = line
        
        // 暂无数据
        let lab2 = UILabel.init(frame: CGRect.init(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight*0.6))
        lab2.textColor = kLabelColor2
        lab2.textAlignment = .center
        lab2.font = kBFont(15)
        lab2.text = "暂无数据".languageText
        lab2.isUserInteractionEnabled = false
        self.noDataLabel = lab2
        
        let icon2 = UIImageView.init(frame: CGRect.init(x:(lab2.c_width() - 60)/2.0, y: (lab2.c_height() - 60)/2.0 - 50, width: 60, height: 60))
        icon2.c_image("232")
        icon2.contentMode = .scaleAspectFit
        lab2.addSubview(icon2)
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        if self.navigationController == nil || (self.navigationController?.viewControllers.count)! <= 1 {
            self.backButton!.isHidden = true
        } else {
            self.backButton!.isHidden = false
            self.backButton!.addTarget(self, action: #selector(navigatiopnBack), for: .touchUpInside)
        }
    }

    
    // MARK:======================================动作响应========================================
    // MARK:导航栏返回
    @objc func navigatiopnBack() -> Void {
        self.navigationController?.popViewController(animated: true)
    }
    
}

